home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Sep / di9809jp / BlastClient / Winsock2.pas < prev   
Pascal/Delphi Source File  |  1998-01-26  |  59KB  |  1,715 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Windows Sockets API v. 2.20 Header File         }
  4. {                            }
  5. {        Prerelease 16.09.96            }
  6. {                            }
  7. {       Base:      WinSock2.h from Winsock SDK 1.6 BETA  }
  8. {                 Delphi 2 RTL Windows32 API Interface  }
  9. {                            }
  10. {       (c) 1996 by Artur Grajek 'AHS'                  }
  11. {    email: c51725ag@juggernaut.eti.pg.gda.pl    }
  12. {*******************************************************}
  13. {                                                       }
  14. {                                                       }
  15. { List of Modifications :                               }
  16. { Removed WS2's type definition of TGUID, and now use   }
  17. { the TGUID type as defined in the D3's COMOBJ unit     }
  18. { Modified by JCP 271197                                }
  19. {                                                       }
  20. {                                                       }
  21. {                                                       }
  22. {*******************************************************}
  23.  
  24. unit WinSock2;
  25.  
  26. interface
  27.  
  28. uses Windows, comobj;// Added COMOBJ for TGUID type reference JCP 271197
  29.  
  30. type
  31.   u_char = Char;
  32.   u_short = Word;
  33.   u_int = Integer;
  34.   u_long = Longint;
  35.   pu_long = ^u_long;
  36.   pu_short = ^u_short;
  37.  
  38. { The new type to be used in all
  39.   instances which refer to sockets. }
  40.   TSocket = u_int;
  41.  
  42. const
  43.   FD_SETSIZE     =   64;
  44.  
  45. type
  46.   PFDSet = ^TFDSet;
  47.   TFDSet = packed record
  48.     fd_count: u_int;
  49.     fd_array: array[0..FD_SETSIZE-1] of TSocket;
  50.   end;
  51.  
  52.   PTimeVal = ^TTimeVal;
  53.   TTimeVal = packed record
  54.     tv_sec: Longint;
  55.     tv_usec: Longint;
  56.   end;
  57.  
  58. const
  59.   IOCPARM_MASK = $7f;
  60.   IOC_VOID     = $20000000;
  61.   IOC_OUT      = $40000000;
  62.   IOC_IN       = $80000000;
  63.   IOC_INOUT    = (IOC_IN or IOC_OUT);
  64.  
  65.   FIONREAD     = IOC_OUT or { get # bytes to read }
  66.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  67.     (Longint(Byte('f')) shl 8) or 127;
  68.   FIONBIO      = IOC_IN or { set/clear non-blocking i/o }
  69.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  70.     (Longint(Byte('f')) shl 8) or 126;
  71.   FIOASYNC     = IOC_IN or { set/clear async i/o }
  72.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  73.     (Longint(Byte('f')) shl 8) or 125;
  74.  
  75.  
  76. const
  77.  
  78. { Protocols }
  79.  
  80.   IPPROTO_IP     =   0;        { Dummy                    }
  81.   IPPROTO_ICMP   =   1;        { Internet Control Message Protocol }
  82.   IPPROTO_IGMP   =   2;        { Internet Group Management Protocol}
  83.   IPPROTO_GGP    =   3;        { Gateway                           }
  84.   IPPROTO_TCP    =   6;        { TCP                       }
  85.   IPPROTO_PUP    =   12;    { PUP                    }
  86.   IPPROTO_UDP    =   17;    { User Datagram Protocol        }
  87.   IPPROTO_IDP    =   22;    { XNS IDP                }
  88.   IPPROTO_ND     =   77;    { UNOFFICIAL Net Disk Protocol    }
  89.  
  90.   IPPROTO_RAW    =   255;
  91.   IPPROTO_MAX    =   256;
  92.  
  93. { Port/socket numbers: network standard functions}
  94.  
  95.   IPPORT_ECHO    =   7;
  96.   IPPORT_DISCARD =   9;
  97.   IPPORT_SYSTAT  =   11;
  98.   IPPORT_DAYTIME =   13;
  99.   IPPORT_NETSTAT =   15;
  100.   IPPORT_FTP     =   21;
  101.   IPPORT_TELNET  =   23;
  102.   IPPORT_SMTP    =   25;
  103.   IPPORT_TIMESERVER  =  37;
  104.   IPPORT_NAMESERVER  =  42;
  105.   IPPORT_WHOIS       =  43;
  106.   IPPORT_MTP         =  57;
  107.  
  108. { Port/socket numbers: host specific functions }
  109.  
  110.   IPPORT_TFTP        =  69;
  111.   IPPORT_RJE         =  77;
  112.   IPPORT_FINGER      =  79;
  113.   IPPORT_TTYLINK     =  87;
  114.   IPPORT_SUPDUP      =  95;
  115.  
  116. { UNIX TCP sockets }
  117.   
  118.   IPPORT_EXECSERVER  =  512;
  119.   IPPORT_LOGINSERVER =  513;
  120.   IPPORT_CMDSERVER   =  514;
  121.   IPPORT_EFSSERVER   =  520;
  122.   
  123. { UNIX UDP sockets }
  124.  
  125.   IPPORT_BIFFUDP     =  512;
  126.   IPPORT_WHOSERVER   =  513;
  127.   IPPORT_ROUTESERVER =  520;
  128.   
  129. { Ports < IPPORT_RESERVED are reserved for
  130.   privileged processes (e.g. root). }
  131.  
  132.   IPPORT_RESERVED    =  1024;
  133.   
  134. { Link numbers }
  135.  
  136.   IMPLINK_IP         =  155;
  137.   IMPLINK_LOWEXPER   =  156;
  138.   IMPLINK_HIGHEXPER  =  158;
  139.  
  140. type
  141.   SunB = packed record
  142.     s_b1, s_b2, s_b3, s_b4: u_char;
  143.   end;
  144.  
  145.   SunW = packed record
  146.     s_w1, s_w2: u_short;
  147.   end;
  148.  
  149.   PInAddr = ^TInAddr;
  150.   TInAddr = packed record
  151.     case integer of
  152.       0: (S_un_b: SunB);
  153.       1: (S_un_w: SunW);
  154.       2: (S_addr: u_long);
  155.   end;
  156.  
  157.   PSockAddrIn = ^TSockAddrIn;
  158.   TSockAddrIn = packed record
  159.     case Integer of
  160.       0: (sin_family: u_short;
  161.           sin_port: u_short;
  162.           sin_addr: TInAddr;
  163.           sin_zero: array[0..7] of Char);
  164.       1: (sa_family: u_short;
  165.           sa_data: array[0..13] of Char)
  166.   end;
  167. type
  168.   PHostEnt = ^THostEnt;
  169.   THostEnt = packed record
  170.     h_name: PChar;
  171.     h_aliases: ^PChar;
  172.     h_addrtype: Smallint;
  173.     h_length: Smallint;
  174.     case integer of
  175.      0: (h_addr_list: ^PChar);
  176.      1: (h_addr: ^PInAddr);
  177.   end;
  178.  
  179.   PNetEnt = ^TNetEnt;
  180.   TNetEnt = packed record
  181.     n_name: PChar;
  182.     n_aliases: ^PChar;
  183.     n_addrtype: Smallint;
  184.     n_net: u_long;
  185.   end;
  186.  
  187.   PServEnt = ^TServEnt;
  188.   TServEnt = packed record
  189.     s_name: PChar;
  190.     s_aliases: ^PChar;
  191.     s_port: Smallint;
  192.     s_proto: PChar;
  193.   end;
  194.  
  195.   PProtoEnt = ^TProtoEnt;
  196.   TProtoEnt = packed record
  197.     p_name: PChar;
  198.     p_aliases: ^Pchar;
  199.     p_proto: Smallint;
  200.   end;
  201.  
  202. const
  203.   INADDR_ANY       = $00000000;
  204.   INADDR_LOOPBACK  = $7F000001;
  205.   INADDR_BROADCAST = $FFFFFFFF;
  206.   INADDR_NONE      = $FFFFFFFF;
  207.  
  208.   ADDR_ANY         = INADDR_ANY;
  209.  
  210. const
  211.   WSADESCRIPTION_LEN     =   256;
  212.   WSASYS_STATUS_LEN      =   128;
  213.  
  214. type
  215.   PWSAData = ^TWSAData;
  216.   TWSAData = packed record
  217.     wVersion: Word;
  218.     wHighVersion: Word;
  219.     szDescription: array[0..WSADESCRIPTION_LEN] of Char;
  220.     szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
  221.     iMaxSockets: Word;
  222.     iMaxUdpDg: Word;
  223.     lpVendorInfo: PChar;
  224.   end;
  225.  
  226.   PTransmitFileBuffers = ^TTransmitFileBuffers;
  227.   TTransmitFileBuffers = packed record
  228.       Head: Pointer;
  229.       HeadLength: DWORD;
  230.       Tail: Pointer;
  231.       TailLength: DWORD;
  232.   end;
  233.  
  234. const
  235.  
  236. { Options for use with [gs]etsockopt at the IP level. }
  237.  (*
  238.   IP_OPTIONS          = 1;
  239.   IP_MULTICAST_IF     = 2;           { set/get IP multicast interface   }
  240.   IP_MULTICAST_TTL    = 3;           { set/get IP multicast timetolive  }
  241.   IP_MULTICAST_LOOP   = 4;           { set/get IP multicast loopback    }
  242.   IP_ADD_MEMBERSHIP   = 5;           { add  an IP group membership      }
  243.   IP_DROP_MEMBERSHIP  = 6;           { drop an IP group membership      }
  244.  
  245.   IP_DEFAULT_MULTICAST_TTL   = 1;    { normally limit m'casts to 1 hop  }
  246.   IP_DEFAULT_MULTICAST_LOOP  = 1;    { normally hear sends if a member  }
  247.    { per socket; must fit in one mbuf }
  248. *)
  249. //
  250.   IP_OPTIONS          = 1;  //* set/get IP options */
  251.   IP_HDRINCL          = 2;  //* header is included with data */
  252.   IP_TOS              = 3;  //* IP type of service and preced*/
  253.   IP_TTL              = 4;  //* IP time to live */
  254.   IP_MULTICAST_IF     = 9;  //* set/get IP multicast i/f  */
  255.   IP_MULTICAST_TTL    = 10; //* set/get IP multicast ttl */
  256.   IP_MULTICAST_LOOP   = 11; //*set/get IP multicast loopback */
  257.   IP_ADD_MEMBERSHIP   = 12; //* add an IP group membership */
  258.   IP_DROP_MEMBERSHIP  = 13; //* drop an IP group membership */
  259.   IP_DONTFRAGMENT     = 14; //* don't fragment IP datagrams */
  260.  
  261. // Option to use with [gs]etsockopt at the IPPROTO_UDP level */
  262.  
  263.    UDP_NOCHECKSUM     = 1;
  264.  
  265. //* Option to use with [gs]etsockopt at the IPPROTO_TCP level */
  266.  
  267.     TCP_EXPEDITED_1122 = $0002;
  268.  
  269.  
  270.  
  271. { This is used instead of -1, since the
  272.   TSocket type is unsigned.}
  273.  
  274.   INVALID_SOCKET        = TSocket(NOT(0));
  275.   SOCKET_ERROR        = -1;
  276.  
  277. { The  following  may  be used in place of the address family, socket type, or
  278.   protocol  in  a  call  to WSASocket to indicate that the corresponding value
  279.   should  be taken from the supplied WSAPROTOCOL_INFO structure instead of the
  280.   parameter itself.
  281.  }
  282.  
  283.   FROM_PROTOCOL_INFO    = -1;
  284.  
  285. { Types }
  286.  
  287.   SOCK_STREAM     = 1;               { stream socket }
  288.   SOCK_DGRAM      = 2;               { datagram socket }
  289.   SOCK_RAW        = 3;               { raw-protocol interface }
  290.   SOCK_RDM        = 4;               { reliably-delivered m